<?php
	$sql="SELECT a.*, b.`name` AS product_type_name
	FROM tbl_product a INNER JOIN tbl_product_type b ON a.product_type_id=b.id";
	if($_GET["product_type_id"]!="")
		$sql.=" WHERE b.id=$_GET[product_type_id]";
	$sql.=" ORDER BY a.product_type_id DESC, a.id DESC";
	$res=mysql_query($sql);
			
	if(!$res)
		dieN(mysql_error());
?>
<form name="f" method="POST">
	<input type="hidden" name="guid"></input>
	<input type="hidden" name="act"></input>
	<input type="hidden" name="image"></input>
	<table class='tbl_view'>
		<tr id='first'>
			<td></td>			
			<td><span>Hình ảnh</span></td>
			<td><span>Mã</span></td>
			<td><span>Tên hàng</span></td>
			<td><span>ĐVT</span></td>
			<!--<td><span>Đơn giá (VNĐ)</span></td>-->
			<td><span>Trích dẫn</span></td>
			<td></td>
		</tr>
		<?php 
		$i=1;
		$flag="";
		$k=0;		
		while($row=mysql_fetch_array($res))
		{
			if($row['product_type_id']!=$flag)
			{
				$flag=$row['product_type_id'];
		?>
		<tr>
			<td id='order'></td>
			<td colspan='5' style='background-color:#cccccc;font-weight:bold;text-transform:uppercase'>
				<?php echo $row['product_type_name'];?>
			</td>
			<td id='manager'>
		</tr>		
		<?php 
			}
		?>
		<tr>
			<td id='order'>
				<span><?php echo($i++);?></span>				
			</td>					
			<td style='padding:0px;margin:0px;height:0px;width:0px'>
				<?php				
				if($row["image"]!="")
				{ 
					$o_image=$image="_thumbs/images/product/$row[image]";
					if(file_exists($o_image))
						$k++;							
				?>
				<img alt="<?php echo $o_image;?>" src="<?php echo $image;?>" />
				<?php
				} 
				?>
			</td>		
			<td><?php echo($row["code"]);?></td>		
			<td><?php echo($row["name"]);?></td>
			<td><?php echo($row["unit"]);?></td>			
			<!--<td style='text-align:right'><?php echo($row["price"]);?></td>-->
			<td><?php echo($row["quote"]);?></td>
			<td id='manager' style='min-width:120px'>
				<?php if($row["focus"]==1){?>
				<span onclick="f.act.value='actionFocus';f.guid.value='<?php echo $row["id"]?>';f.submit();" style='font-weight:bold'>+</span>
				<?php }else{?>
				<span onclick="f.act.value='actionFocus';f.guid.value='<?php echo $row["id"]?>';f.submit();" style='font-weight:bold'>-</span>	
				<?php }?>
				<span onclick="f.act.value='update';f.guid.value='<?php echo $row["id"]?>';f.submit();">Sửa</span>
				<span onclick="f.image.value='<?php echo $row["image"]; ?>';f.act.value='actionDelete';f.guid.value='<?php echo $row["id"]?>';f.submit();">Xóa</span>
			</td>
		</tr>		
		<?php 
		}
		echo '<!--TOTAL: '.$k.'-->';
		?>
		<tr id='last'>
			<td colspan='6'>
				<span onclick="f.act.value='insert';f.submit();" style='cursor:pointer'>
					Thêm
				</span>
			</td>
			<td></td>
		</tr>
	</table>
</form>

